<?php
// 本类由系统自动生成，仅供测试用途
namespace Qiaoxi\Controller;
use Think\Controller;
use Think\Db;
class IndexController extends Controller {
	
	public function index(){
		$this->display();
	}
	public function yjphb()
	{
		$this->display();
	}
	public function  login (){
		if (!IS_POST)
			$this->display();
		else
		{
			echo I('username').I('password');
		}
	}
	public function showDept()
	{
		$username="hezuo";
		$password = "qiaoxifangchanhezuo$&";
		$dsn = "dblib:host=118.31.69.203:1502;dbname=Agency;charset=utf8;";
		$dbh = new PDO($dsn, $username, $password);
		$stmt = $dbh->prepare("SELECT * FROM Department");
		$stmt->execute();
		$this->display('ok');
		
		
		
		/*$model=M('Department');
		$list=$model->where('FlagSale=1')->select();
		$this->assign("list",$list);
		$this->display();
		*/
	}
	public function showEmployee()
	{
		$model=M('Employee');
		$DeptID=I('did');
		$list=$model->where("DeptID='%s'",$DeptID)->select();
		$this->assign("list",$list);
		$this->display();
	}
	public function insert()
	{
		//这里由于数据库里的表名是c5_user，所以不能直接调用M('user'),https://blog.csdn.net/zhangzhangdan/article/details/78601919
		$model=M('','c5_User');
		for ($i=0;$i<=10000;$i++)
		{
			$data=array(
					'username'=>'zhangsan'.$i,
					'password'=>md5(microtime(true)),
					'create_at'=>time(),
					'updated_at'=>time(),
			);
			
			echo $model->add($data)?1:0,'<br/>';
		}
		echo 'ok';
	}
	public function listProperty()
	{
		$p=D('Property');
		$data=$p->query("SELECT  top 30 e.EstateName,p.propertyid,p.CountF+p.CountT+p.CountW+p.CountY AS hx ,p.Square,p.Price ,p.Floor ,f.content 
		FROM Property p,Estate e,Follow f WHERE p.EstateID=e.EstateID AND  p.PropertyID=f.PropertyID and status='有效' AND f.Content LIKE '%请展示到电视%' ORDER BY p.ModDate DESC, p.LastFollowDate desc");
		$this->assign('data',$data);
		$this->display();
	}
	public function showimgfromdb()
	{
		header('content-type:image/jpeg');
		$model=M('Photo');
		//$PhotoID = I('PhotoID');
		$PropertyID=  I('PropertyID');

		$data=$model->query("SELECT TOP 1 PhotoData FROM photo WHERE PropertyID='".$PropertyID."'");
		
		if($data){
			header('content-type:image/jpeg');
			echo $data[0];
			exit();
		}
	}
}